function [out, Maturity, debtoverhang] = debtmat_given_equity(targetequity, firmtype, struct_input, isplot)

startpoint = 0.01;
endpoint = 30;
if isplot
    rangetocheck = [0.01, 30];

    xvec = linspace(rangetocheck(1), rangetocheck(2), 100)';
    equityvec = nan(100,1);
    equityvec_single = nan(100,1);

    StockSpec_single = stockspec(struct_input.StockSpec.Sigma(1), sum(struct_input.StockSpec.AssetPrice));
    struct_input_single = struct_input;
    struct_input_single.StockSpec = StockSpec_single;
    for i = 1:length(xvec)
        debtmat_dur = duration([xvec(i)*365*24, 0, 0]);
        Maturity = struct_input.Settle + debtmat_dur;

        equityvec_single(i) = optstocksensbybls(struct_input.RateSpec, StockSpec_single, struct_input.Settle, Maturity, struct_input.OptSpec, struct_input.Strike, 'OutSpec', {'Price'});
        equityvec(i) = basketsensbyju(struct_input.RateSpec, struct_input.StockSpec, struct_input.OptSpec, struct_input.Strike, struct_input.Settle, Maturity, 'OutSpec', {'Price'});
    end
    figure
    plot(xvec, equityvec)
    hold on
    plot(xvec, repmat(targetequity, 100, 1))
    plot(xvec, equityvec_single)
    hold off
    legend([{firmtype}, {'target'}, {'single'}])
    zeroid = find((equityvec - targetequity) > 0);
    endpoint = xvec(zeroid(1) + 2);
    startpoint = rangetocheck(1);
end

out = fzero(@(x)(equity_given_debtmat(struct_input, firmtype, x) - targetequity), [startpoint endpoint]);

[~, Maturity, debtoverhang] = equity_given_debtmat(struct_input, firmtype, out);

end